<script setup>
import { showToast } from "vant";
import { ref, onMounted } from "vue";
import { useRoute } from "vue-router";

const list = ref([
	{
		id: 1,
		type: 1,
		title: "服务态度评价",
		subject: "佩戴工作证，主动介绍，礼貌称呼",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},
	{
		id: 2,
		type: 1,
		title: "服务态度评价",
		subject: "护理操作有告知和解释",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},
	{
		id: 3,
		type: 1,
		title: "服务态度评价",
		subject: "护理结束征求意见",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},

	{
		id: 4,
		type: 1,
		title: "服务过程与技术",
		subject: "您预约居家护理当天，护士联系您并确认居家护理时间及所需物品",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},
	{
		id: 5,
		title: "服务过程与技术",
		type: 1,
		subject: "护士进入您家前，核对病人身份信息",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},
	{
		id: 6,
		title: "服务过程与技术",
		type: 1,
		subject: "护理方案、耗材使用经您或您家属知情同意 ",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},
	{
		id: 7,
		title: "服务过程与技术",
		type: 1,
		subject: "护理技术 ",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},
	{
		id: 8,
		title: "服务过程与技术",
		type: 1,
		subject: "隐私保护 ",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},
	{
		id: 9,
		title: "服务过程与技术",
		type: 1,
		subject: "耐心给予健康教育或指导注意事项 ",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},
	{
		id: 10,
		title: "服务过程与技术",
		type: 1,
		subject: "医疗废物分类放置，护士带回 ",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},
	{
		id: 11,
		title: "服务过程与技术",
		type: 1,
		subject: "不收受馈赠和礼物、不推销物品及耗材 ",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},

	{
		id: 12,
		title: "服务效果",
		type: 1,
		subject: "护理效果 ",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},

	{
		id: 13,
		title: "服务态度",
		type: 1,
		subject: "礼貌称呼，耐心讲解",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},

	{
		id: 14,
		title: "服务效率",
		type: 1,
		subject: "及时接听电话并解决问题",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},

	{
		id: 15,
		title: "服务质量",
		type: 1,
		subject: "平台操作便捷性",
		score: 0,
		options: [
			{ answer: "非常满意", value: 5 },
			{ answer: "满意", value: 4 },
			{ answer: "一般", value: 3 },
			{ answer: "不满意", value: 2 },
			{ answer: "非常不满意", value: 1 },
		],
	},
	{ id: 16, subject: "你的建议", type: 0, result: "" },
]);

const route = useRoute();
const { userId, patientId, orderId, doctorId, doctorName, institutionName, readonly } = route.query;

const listTitle = [
	"mannerA",
	"mannerB",
	"mannerC",
	"skillA",
	"skillB",
	"skillC",
	"skillD",
	"skillE",
	"skillF",
	"skillG",
	"skillH",
	"effect",
	"platManner",
	"platEfficiency",
	"platQuality",
	"suggestion",
];

// 获取记录
const getList = () => {
	const params = {
		doctorId,
		userId,
		orderId,
	};
	console.log(params);
	/* 	const res = await Evaluate(params);
	if (res.code == "0000") {
		let dataList = res.dataList[0];

		let list = listTitle;
		for (let i = 0; i < list.length; i++) {
			if (listTitle[i] == "suggestion") {
				listTitleData[i].result = dataList[list[i]];
			} else {
				listTitleData[i].score = dataList[list[i]];
			}
		}
	} */
};
onMounted(() => {
	getList();
});

const onSubmit = async () => {
	const params = {
		userId,
		orderId,
		doctorId,
		patientId,
	};
	const arr = list.value;
	const titleList = listTitle.value;
	let aids = 0;
	arr.forEach((item, i) => {
		if (item.type === 1) {
			if (item.score !== 0) {
				params[titleList[i]] = item.score;
				aids = i + 1;
			} else {
				showToast("请全部填写完成后提交");
				// return
			}
		} else if (item.type === 0) {
			if (item.result !== "") {
				params[titleList[i]] = item.result;
				aids = i + 1;
			} else {
				showToast("请全部填写完成后提交");
			}
		}
	});
	if (aids === arr.length) {
		/* 	const res = await AddEvaluate(params);
		if (res.code == "0000") {
			$toast(res.msg);
			$router.replace({
				path: "/user/order-list",
			});
		} */
	}
};
</script>
<template>
	<div class="m-[10px] rounded-[10px] bg-white px-[10px] py-[2px]">
		<div class="bid-b flex justify-between p-[10px]">
			医院名称 <span>{{ institutionName }}</span>
		</div>
		<div class="flex justify-between p-[10px]">
			医护姓名 <span>{{ doctorName }}</span>
		</div>
	</div>
	<div v-for="item in list" :key="item.id" class="m-[10px] rounded-[10px] bg-white p-[10px]">
		<div class="text-[16px]">{{ item.id + "、" + item.subject }}</div>
		<div class="indent-5 text-[#9b9b9b]">{{ item.title }}</div>
		<van-radio-group v-model="item.score">
			<div class="grid grid-cols-2 gap-[6px]">
				<van-radio v-for="(ik, k) in item.options" :key="k" icon-size="4vw" :name="ik.value">{{ ik.answer }}</van-radio>
			</div>
		</van-radio-group>
		<van-field
			v-if="item.type == 0"
			v-model="item.result"
			rows="3"
			autosize
			type="textarea"
			maxlength="200"
			placeholder="请输入您的建议"
			:readonly="JSON.parse(readonly)"
		/>
	</div>

	<div class="py-[40px]"></div>
	<!-- 按钮 -->
	<div class="fixed bottom-0 w-[375px] bg-[#ffffff] px-[20px] py-[10px]">
		<div
			@click="onSubmit"
			class="rounded-[20px] bg-gradient-to-r from-[#4d90f5] to-[#357efe] py-[10px] text-center text-[#ffffff]"
		>
			提交
		</div>
	</div>
</template>
<style>
.van-cell {
	padding: 0 !important;
}
.van-field .van-field__control {
	background: #f7f9fa;
	bid-radius: 6px;
	padding: 2px 8px;
}
.van-radio-group {
	padding: 10px 0 0 20px;
	font-size: 13px;
}
</style>
